package com.wangxinrou.wangxinrou_surprisemeal.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wangxinrou.wangxinrou_surprisemeal.mapper.FeedbackMapper;
import com.wangxinrou.wangxinrou_surprisemeal.model.Feedback;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FeedbackService {
    @Autowired
    private FeedbackMapper feedbackMapper;

    // 获取所有反馈
    public List<Feedback> getAllFeedbacks() {
        return feedbackMapper.selectList(null);
    }

    // 根据用户ID获取反馈
    public List<Feedback> getFeedbackByUserId(int userId) {
        return feedbackMapper.selectList(new QueryWrapper<Feedback>().eq("user_id", userId));
    }

    // 根据餐馆ID获取反馈
    public List<Feedback> getFeedbackByRestaurantId(int restaurantId) {
        return feedbackMapper.selectList(new QueryWrapper<Feedback>().eq("restaurant_id", restaurantId));
    }

    // 添加反馈
    public boolean addFeedback(Feedback feedback) {
        return feedbackMapper.insert(feedback) > 0;
    }

    // 更新反馈
    public boolean updateFeedback(Feedback feedback) {
        return feedbackMapper.updateById(feedback) > 0;
    }

    // 根据ID删除反馈
    public boolean deleteFeedback(int feedbackId) {
        return feedbackMapper.deleteById(feedbackId) > 0;
    }
}
